package com.sskj.mine.http;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.bean.UserData;
import com.sskj.mine.bean.AboutUsBean;
import com.sskj.mine.bean.AddressList;
import com.sskj.mine.bean.AssetBean;
import com.sskj.mine.bean.CoinFeeBean;
import com.sskj.mine.bean.CustomListBean;
import com.sskj.mine.bean.FbShop;
import com.sskj.mine.bean.ImgUrlBean;
import com.sskj.mine.bean.LockHouseBean;
import com.sskj.mine.bean.OtherRecordBean;
import com.sskj.mine.bean.PayWayBean;
import com.sskj.mine.bean.QrCodeBean;
import com.sskj.mine.bean.RechargeInfoBean;
import com.sskj.mine.bean.RechargeListBean;
import com.sskj.mine.bean.SysBean;
import com.sskj.mine.bean.TeamBean;
import com.sskj.mine.bean.UserAgreeMent;

import java.io.File;
import java.util.List;


/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService implements IHttpService {


    /**
     * 手机号注册
     */
    @Override
    public PostRequest<HttpData> register(String account, String pswd, String pswd1, String code, String invitationCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.REGISTER)
                .params("mobile", account)  // 手机号或者邮箱
                .params("code", code)  // 验证码
                .params("opwd", pswd)
                .params("opwd1", pswd1)  // 重复密码
                .params("tjuser", invitationCode);  // 推荐码邀请码
    }


    /**
     * 获取短信验证码---codeType 1代表注册  2代表重置密码
     *
     * @param mobile 手机号
     * @param type
     * @return
     */
    @Override
    public PostRequest<HttpData> sendCode(String mobile, String type) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
                .params("type", type)
                .params("mobile", mobile);
    }


    /**
     * 登录
     *
     * @param pswd    密码
     * @param account 账号
     * @return
     */
    @Override
    public PostRequest<HttpData<UserData>> login(String account, String pswd) {
        return OkGo.<HttpData<UserData>>post(HttpConfig.BASE_URL + HttpConfig.LOGIN)
                .params("opwd", pswd)
                .params("mobile", account);
    }


    /**
     * 邮箱注册
     *
     * @param email          邮箱号
     * @param pswd           密码
     * @param code           验证码
     * @param invitationCode 邀请码
     * @return
     */
    @Override
    public PostRequest<HttpData> registerEmail(String email, String pswd, String code, String invitationCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.REGISTER_WITH_EMAIL)
                .params("email", email)
                .params("pswd", MD5Util.getMd5Value(pswd))
                .params("code", code)
                .params("invitationCode", invitationCode);
    }


    /**
     * @param email 邮箱号
     * @return
     */
    @Override
    public PostRequest<HttpData> sendEmailCode(String email) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL_CODE)
                .params("type",2)
                .params("email", email);
    }

    /**
     * @param email 邮箱号
     * @return
     */
    @Override
    public PostRequest<HttpData> sendEmailCode1(String email) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL_CODE)
                .params("type",1)
                .params("email", email);
    }

    @Override
    public PostRequest<HttpData> checkCode(String mobile, String code, String type) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHECK_CODE)
                .params("type", type)
                .params("code", code)
                .params("mobile", mobile);
    }


    /**
     * 获取注册协议
     *
     * @return
     */
    @Override
    public GetRequest<HttpData<UserAgreeMent>> getXieyi() {
        return OkGo.<HttpData<UserAgreeMent>>get(HttpConfig.BASE_URL + HttpConfig.GET_XIEYI);
    }

    @Override
    public GetRequest<HttpData<QrCodeBean>> getUrlCode() {
        return OkGo.<HttpData<QrCodeBean>>get(HttpConfig.BASE_URL + HttpConfig.GET_TUIGUANG);
    }


    /**
     * 邮箱号重置密码
     *
     * @param opwd   验证码
     * @param opwd1  新密码
     * @param code   验证码
     * @param mobile 用户账号/邮箱
     * @return
     */
    @Override
    public PostRequest<HttpData> resetPwdWithEmail(String opwd, String opwd1, int code, String mobile) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.RESET_PWD_WITH_EMAIL)
                .params("opwd", opwd)
                .params("opwd1", opwd)
                .params("code", code)
                .params("mobile", mobile);
    }


    /**
     * 手机号重置密码
     *
     * @param code    验证码
     * @param pswd    新密码
     * @param account 账号
     * @return
     */
    @Override
    public PostRequest<HttpData> resetPwd(String code, String pswd, String account) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.RESET_PWD)
                .params("code", code)
                .params("pswd", MD5Util.getMd5Value(pswd))
                .params("account", account);
    }


    /**
     * 设置支付密码
     *
     * @param code     验证码
     * @param tradePwd 支付密码
     * @return
     */
    @Override
    public PostRequest<HttpData> setPayPwd(String code, String tradePwd, String mobile) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SET_PAY_PWD)
                .params("code", code)
                .params("tpwd", tradePwd)
                .params("check_tpwd", tradePwd)
                .params("mobile", mobile);
    }


    /**
     * 上传图片
     *
     * @param file 文件
     * @return
     */
    @Override
    public PostRequest<HttpData<ImgUrlBean>> uploadImg(File file) {
        return OkGo.<HttpData<ImgUrlBean>>post(HttpConfig.BASE_URL + HttpConfig.UPLOAD_IMG)
                .params("file_pic", file);
    }


    /**
     * 绑定邮箱
     *
     * @param code  验证码
     * @param email 邮箱号
     * @return
     */
    @Override
    public PostRequest<HttpData> bindEmail(String code, String email) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_EMAIL)
                .params("email", email)
                .params("code", code);
    }


    /**
     * 实名认证
     *
     * @param username       用户名
     * @param idCardNo       身份证号
     * @param idCardFrontImg 前身份证
     * @param idCardBackImg  后身份证
     * @param selfieImg      手持
     * @return
     */
    @Override
    public PostRequest<HttpData> verify(String username, String idCardNo, String idCardFrontImg, String idCardBackImg, String selfieImg, String type, String account) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.VERIFY_IDENT)
                .params("realname", username)
                .params("card_num", idCardNo)
                .params("type", type)
                .params("mobile", account.contains("@") ? null : account)
                .params("email", account.contains("@") ? account : null)
                .params("idCardFrontImg", idCardFrontImg)
                .params("idCardBackImg", idCardBackImg)
                .params("selfieImg", selfieImg);
    }

    /**
     * 实名认证
     *
     * @param cardNum  证件号
     * @param realName 真实姓名
     * @param type     认证类型 1 身份证 2 护照
     * @param cardimg1 身份证正面/护照
     * @param cardimg2 身份证反面
     * @param cardimg3 手持身份证
     * @return
     */
    @Override
    public PostRequest<HttpData> realNameVerify(String cardNum, String realName, int type, String cardimg1, String cardimg2, String cardimg3) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.VERIFY_IDENT)
                .params("card_num", cardNum)
                .params("realname", realName)
                .params("type", type)
                .params("mobile", "")
                .params("email", "")
                .params("cardimg1", cardimg1)
                .params("cardimg2", cardimg2)
                .params("cardimg3", cardimg3);
    }


    /**
     * 获取资产列表
     *
     * @return
     */
    @Override
    public PostRequest<HttpData<AssetBean>> getAssets() {
        return OkGo.<HttpData<AssetBean>>post(HttpConfig.BASE_URL + HttpConfig.ASSET_LIST);
    }


    /**
     * 获取提现手续费
     *
     * @param pid 币种码
     * @return
     */
    @Override
    public PostRequest<HttpData<CoinFeeBean>> getWithdrawFee(String pid) {
        return OkGo.<HttpData<CoinFeeBean>>post(HttpConfig.BASE_URL + HttpConfig.GET_COIN_FEE)
                .params("pid", pid);
    }


    /**
     * 充值
     *
     * @param code 币种码
     * @return
     */
    @Override
    public GetRequest<HttpData<RechargeInfoBean>> recharge(String code) {
        return OkGo.<HttpData<RechargeInfoBean>>get(HttpConfig.BASE_URL + HttpConfig.RECHARGE_URL)
                .params("wall_type", code);
    }

    /**
     * 提现
     *
     * @param code    验证码
     * @param tpwd    支付密码
     * @param num     金额
     * @param address 钱包地址
     * @param pid     币种码
     * @param account 手机号/邮箱号
     * @return
     */
    @Override
    public PostRequest<HttpData> withdraw(String code, String tpwd, String num, String address, String pid, String account) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.WITHDRAW)
                .params("code", code)
                .params("tpwd", MD5Util.getMd5Value(tpwd))
                .params("num", num)
                .params("address", address)
                .params("pid", pid)
                .params("account", account);
    }

    /**
     * 冲提币记录
     *
     * @return
     */
    @Override
    public GetRequest<HttpData<PageBean<RechargeListBean>>> getAssetRecord(int page, int pageSize, String type, String stockCode) {
        return OkGo.<HttpData<PageBean<RechargeListBean>>>get(HttpConfig.BASE_URL + HttpConfig.ASSET_RECORD)
                .params("p", page)
                .params("size", pageSize)
                .params("type", type)
                .params("pid", stockCode);
    }

    @Override
    public PostRequest<HttpData<PageBean<OtherRecordBean>>> getOtherRecord(int page, int pageSize, String stockCode) {
        return OkGo.<HttpData<PageBean<OtherRecordBean>>>post(HttpConfig.BASE_URL + HttpConfig.OTHER_RECORD)
                .params("p", page)
                .params("size", pageSize)
                .params("pid", stockCode);
    }


    /**
     * 添加钱包地址
     *
     * @param type   类型 ETH 1，BTC 2，BCH 3
     * @param addr   钱包地址
     * @param code   币种码
     * @param remark 备注
     * @return
     */
    @Override
    public PostRequest<HttpData> addWalletAddress(String type, String addr, String code, String remark) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_ADD)
                .params("type", type)
                .params("address", addr)
                .params("notes", remark);
    }


    /**
     * 获取钱包列表
     *
     * @return
     */
    @Override
    public GetRequest<HttpData<AddressList>> getWalletList() {
        return OkGo.<HttpData<AddressList>>get(HttpConfig.BASE_URL + HttpConfig.ADDRESS_LIST);
    }


    /**
     * 删除钱包地址
     *
     * @param id 钱包地址Id
     * @return
     */
    @Override
    public PostRequest<HttpData> delWalletAddress(String id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_DEL)
                .params("act", "del")
                .params("id", id);
    }

    @Override
    public PostRequest<HttpData> changePwd(String originPwd, String newPwd, String newPwdAgain) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHANGE_PWD)
                .params("oldpwd", originPwd)
                .params("opwd", newPwd)
                .params("opwd1", newPwdAgain);

    }

    @Override
    public PostRequest<HttpData> bindMobile(String mobile, String code) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_MOBILE)
                .params("mobile", mobile)
                .params("code", code);

    }

    @Override
    public GetRequest<HttpData<AboutUsBean>> getSys() {
        return OkGo.<HttpData<AboutUsBean>>get(HttpConfig.BASE_URL + HttpConfig.GET_SYS);

    }

    @Override
    public GetRequest<HttpData<PayWayBean>> getPayType() {
        return OkGo.<HttpData<PayWayBean>>get(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_LIST);
    }

    @Override
    public PostRequest<HttpData<LockHouseBean>> getLockHouseType(String pid) {
        return OkGo.<HttpData<LockHouseBean>>post(HttpConfig.BASE_URL + HttpConfig.LOCK_HOUSE_LIST)
                .params("pid", pid);
    }

    @Override
    public PostRequest<HttpData> commitLockHouse(String id, String num, String tpwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.COMMIT_LOCK_HOUSE)
                .params("id", id)
                .params("num", num)
                .params("tpwd", MD5Util.getMd5Value(tpwd));
    }

    @Override
    public PostRequest<HttpData> addPayWay(
            String payId                //添加或者编辑，add,edit
            , String payType            //支付类型：wx,alipay,backcard,paypal
            , String tradePwd           //支付密码
            , String wxAccount          //微信号
            , String wxImg              //微信图片地址
            , String alipayAccount      //支付宝
            , String aliImg             //支付宝图片地址
            , String bankCardNo         //银行卡账号
            , String bankCardOpenBank   //开户行支行
            , String bankCardType       //银行
            , String name               //用户姓名
            , String palAccount) {      //paypal账户
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADD_PAY_WAY)
                .params("tpwd", MD5Util.getMd5Value(tradePwd))   // 最开始接口传两个密码
                .params("act", payId)
                .params("type", payType)
                .params("wx", wxAccount)
                .params("wx_img", wxImg)
                .params("alipay", alipayAccount)
                .params("ali_img", aliImg)
                .params("bank", bankCardType)
                .params("branch", bankCardOpenBank)
                .params("bank_car", bankCardNo)
                .params("name", name)
                .params("pal_account", palAccount);
    }

    @Override
    public PostRequest<HttpData> applyShop(String status) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.APPLY_SELLER)
                .params("isShopStatus", status);
    }

    @Override
    public PostRequest<HttpData<Object>> togglePayType(String type, String val) {
        return OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.TOGGLE_PAY)
                .params("type", type)
                .params("val", val);
    }

    @Override
    public PostRequest<HttpData<List<FbShop>>> moneyUsed(String name, String type) {
        return OkGo.<HttpData<List<FbShop>>>post(HttpConfig.BASE_URL + HttpConfig.FB_SHOP)
                .params("name", name)
                .params("type", type);
    }

    @Override
    public PostRequest<HttpData<PageBean<CustomListBean>>> myClient(int page) {
        return OkGo.<HttpData<PageBean<CustomListBean>>>post(HttpConfig.BASE_URL + HttpConfig.GET_CLIENT)
                .params("p", page)
                .params("size", 20);
    }

    @Override
    public PostRequest<HttpData<TeamBean>> clientNum() {

        return OkGo.<HttpData<TeamBean>>post(HttpConfig.BASE_URL + HttpConfig.GET_CLIENT)
                .params("p", 1)
                .params("size", 20);
    }
}